﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FuzzScript
{
    /// <summary>
    /// Node containing a list of antecedent predicates
    /// </summary>
    class PredicatesNode : Node
    {
        /// <summary>
        /// Generates the equivalent c# code for this node. The execution of this node actually exectes all the
        /// predicates, so this is achieved in a sigle method that is called duting execution. Important to 
        /// note that each predicate is actually a method that computes the DOM for the predicate.
        /// Method if of the form:
        ///     private void ExecutePredicates()
        ///     {
        ///         m_PredicateX_DOM = PredicateX();
        ///         .
        ///         .
        ///         .
        ///         for all predicates
        ///     }
        /// </summary>
        /// <returns></returns>
        public override string Generate()
        {
            StringBuilder sCode = new StringBuilder();

            sCode.Append(base.Generate());
            sCode.Append("private void ExecutePredicates()\n{");

            FuzzyPredicate pred = null;

            for (int i = 0; i < m_SiblingNodes.Count; i++)
            {
                pred = (FuzzyPredicate)m_SiblingNodes[i];

                sCode.Append(SymbolTable.AttributePredicateValue(pred.Name));
                sCode.Append("=");
                sCode.Append(SymbolTable.MethodPredicate(pred.Name));
                sCode.Append("();\n");
            }

            sCode.Append("\n}");

            return sCode.ToString();            
        }
    }



}
